package ms.unicorn.diagram.edit.parts;

import ms.unicorn.diagram.part.UnicornVisualIDRegistry;

import org.eclipse.draw2d.Label;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.tooling.runtime.directedit.locator.CellEditorLocatorAccess;
import org.eclipse.gmf.tooling.runtime.directedit.locator.LabelCellEditorLocator;
import org.eclipse.gmf.tooling.runtime.directedit.locator.TextCellEditorLocator;
import org.eclipse.gmf.tooling.runtime.directedit.locator.VerticalLabelCellEditorLocator;
import org.eclipse.gmf.tooling.runtime.draw2d.labels.VerticalLabel;

/**
 * @generated
 */
public class UnicornEditPartFactory implements EditPartFactory {

	/**
	 * @generated
	 */
	public EditPart createEditPart(EditPart context, Object model) {
		if (model instanceof View) {
			View view = (View) model;
			switch (UnicornVisualIDRegistry.getVisualID(view)) {

			case DiagramEditPart.VISUAL_ID:
				return new DiagramEditPart(view);

			case EntityEditPart.VISUAL_ID:
				return new EntityEditPart(view);

			case EntityElementTypeEditPart.VISUAL_ID:
				return new EntityElementTypeEditPart(view);

			case EntityNameTextEditPart.VISUAL_ID:
				return new EntityNameTextEditPart(view);

			case RelationEditPart.VISUAL_ID:
				return new RelationEditPart(view);

			case RelationElementTypeEditPart.VISUAL_ID:
				return new RelationElementTypeEditPart(view);

			}
		}
		return createUnrecognizedEditPart(context, model);
	}

	/**
	 * @generated
	 */
	private EditPart createUnrecognizedEditPart(EditPart context, Object model) {
		// Handle creation of unrecognized child node EditParts here
		return null;
	}

	/**
	 * @generated NOT
	 */
	public static CellEditorLocator getTextCellEditorLocator(
			ITextAwareEditPart source) {
		return CellEditorLocatorAccess.INSTANCE
				.getTextCellEditorLocator(source);
		/*if (source.getFigure() instanceof WrappingLabel) {
			return new TextCellEditorLocatorEx((WrappingLabel) source.getFigure());
		}
		if (source.getFigure() instanceof VerticalLabel) {
			return new VerticalLabelCellEditorLocator((VerticalLabel) source.getFigure());
		}
		return new LabelCellEditorLocator((Label) source.getFigure());*/
	}

}
